package com.li.day.day15;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;

public class Test extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("gbk");
        String d = new String( req.getParameter("zhanghao").getBytes("iso-8859-1"),"utf-8");
        System.out.println("这是一个dopost");
        // resp.setHeader("Content-type","text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        if (d.equals("张三")){
            resp.sendRedirect("a.html");
        }
        else {
            resp.sendRedirect("index.jsp");
        }
       //转发 req.getRequestDispatcher("te").forward(req,resp);
        System.out.println(new String(req.getParameter("zhanghao").getBytes("iso-8859-1"),"utf-8"));
       // System.out.println(req.getParameter("hai"+new String( req.getParameter("zhanghao").getBytes("iso-8859-1"),"utf-8")));
      //  System.out.println(req.getParameter("mima"));
      //  System.out.println(req.getParameter(new String( req.getParameter("aihao").getBytes("iso-8859-1"),"utf-8")));
      //  System.out.println(req.getParameter("sex"));
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("这是一个doget");
        this.doPost(req, resp);
    }
}
